var app = getApp();
var util = require('../../../utils/util.js');

Page({
    data: {
        imgList:"",
        newsDet:"",
        newsText:"",
        newsId:"",
        imgUrl:app.globalData.imgUrl,
        systemInfo:{},
        scrollFlag:true
    },
    onLoad: function (e) {
        var that = this;
        var currentId=e.id;
        wx.getSystemInfo({
            success:function(res){
              that.setData({
                systemInfo:res,
                navH: app.globalData.navHeight
              })
            }
        });
        that.setData({
            newsId: currentId
        });
        that.getNewsDet();
    },
    onShareAppMessage() {
        var that=this;
        return {
          title: '在海花岛这样订房也不错，快看快约！',
          //path: '/pages/news/detail/news-det?id='+that.data.newsId
          //path: 'pages/index/index?url=/pages/news/detail/news-det?id=' + that.data.newsId
          path: 'pages/index/index?url=/pages/news/detail/news-det&id=' + that.data.newsId
        }
    },
    onPageScroll:function(e){
        var that = this;
        if(e.scrollTop>=140){
            that.setData({
                scrollFlag: false
            });
        }else{
            that.setData({
                scrollFlag: true
            });
        }
    },
    getNewsDet:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/articleDetails",
            data: {
                id: that.data.newsId
            },
            header: {  
                'content-type': 'application/json' 
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var newsData = res.data.data;
                    var newsBanner = newsData.pics.split(',');
                    var newsBody=newsData.body;
                    var newsTextCode=util.baseDecode(newsBody);  //base64解码
                    that.setData({
                        newsDet: newsData,
                        newsText:newsTextCode,
                        imgList:newsBanner
                    })
                }
            },
            
        });
    },
    navBack: function () {
        wx.reLaunch({
            url: '../list/news-list'
        })
    },
})